import time
from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.common.by import By

class TestRubin():
    def setup(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()

    #此案例主要展示移动到某个元素move_to_element
    def test_baidu(self):
        self.driver.get('https://baidu.com/')
        action = ActionChains(self.driver)
        element_sz = self.driver.find_element(By.ID,'s-usersetting-top')
        action.move_to_element(element_sz)
        time.sleep(3)
        action.click(element_sz)
        action.perform()

    def test_send_keys(self):
        self.driver.get('https://pan.rubinchu.com/')
        action = ActionChains(self.driver)
        element1 = self.driver.find_element(By.XPATH,'//*[@id="app"]/div/div/div[1]/label[1]/input')
        action.click(element1)
        action.send_keys('alitest').pause(2)
        action.send_keys(Keys.SPACE).pause(2) #Keys后面可以跟任何对键盘的操作
        action.send_keys('123').pause(2)
        action.send_keys(Keys.BACK_SPACE).pause(2)
        action.send_keys(Keys.CONTROL)
        action.perform()
